﻿Imports System.Data.SqlClient
Imports QuanLyBanChau.HoaDon
Public Class HoaDon_dao

    Public Shared Sub insertHoaDondao(ByVal HoaDon As HoaDon)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(7) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("insert_HoaDon", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(0) = New SqlParameter(" @Mahoadon", SqlDbType.VarChar, 10)
        para(0).Value = HoaDon.Mahoadon
        cmd.Parameters.Add(para(0))
        para(1) = New SqlParameter(" @Makhachhang", SqlDbType.NVarChar, 10)
        para(1).Value = HoaDon.Makhachhang
        cmd.Parameters.Add(para(1))

        para(2) = New SqlParameter(" @Ngayxuathoadon", SqlDbType.DateTime)
        para(2).Value = HoaDon.Ngayxuathoadon
        cmd.Parameters.Add(para(2))


        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub


    Public Shared Sub DeleteHoaDondao(ByVal Mahoadon)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(1) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Delete_HoaDon", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(1) = New SqlParameter(" @Mahoadon", SqlDbType.VarChar, 10)
        para(1).Value = Mahoadon
        cmd.Parameters.Add(para(1))
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub
    Public Shared Function Get_HoaDondao()
        Dim conn As SqlConnection
        conn = dataprovider.Connection()
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
        da.SelectCommand = New SqlCommand
        da.SelectCommand.Connection = conn
        da.SelectCommand.CommandType = CommandType.StoredProcedure
        da.SelectCommand.CommandText = "Get_HoaDon"
        da.Fill(dt)
        Return dt
    End Function


    Public Shared Sub UpdateHoaDondao(ByVal HoaDon As HoaDon)
        Dim conn As SqlConnection
        Dim cmd As SqlCommand
        Dim para(7) As SqlParameter
        conn = dataprovider.Connection()
        cmd = New SqlCommand("Update_HoaDon", conn)
        cmd.CommandType = CommandType.StoredProcedure
        para(0) = New SqlParameter(" @Mahoadon", SqlDbType.VarChar, 10)
        para(0).Value = HoaDon.Mahoadon
        cmd.Parameters.Add(para(0))
        para(1) = New SqlParameter(" @Makhachhang", SqlDbType.NVarChar, 10)
        para(1).Value = HoaDon.Makhachhang
        cmd.Parameters.Add(para(1))

        para(2) = New SqlParameter(" @Ngayxuathoadon", SqlDbType.DateTime)
        para(2).Value = HoaDon.Ngayxuathoadon
        cmd.Parameters.Add(para(2))


        cmd.ExecuteNonQuery()
        cmd.Dispose()
        conn.Close()
    End Sub
End Class
